#include "PublisherPlugin.h"

#include <ctkPluginContext.h>

#include <iostream>

#include "../../Base/data.h"
#include "service/event/ctkEventConstants.h"
Q_DECLARE_METATYPE(data);
PublisherPlugin::PublisherPlugin(ctkPluginContext* context)
    : ctk_plugin_context_(context) {
  publisher_plugin_widget_ = new PublisherPluginWidget();
  // 注册监听信号
  ctkDictionary ctk_dic;
  ctk_dic.insert(ctkEventConstants::EVENT_TOPIC, "EventPublisherPlugin");
  ctk_plugin_context_->registerService<ctkEventHandler>(this, ctk_dic);

  ctk_dic.insert(ctkEventConstants::EVENT_TOPIC, "mesg");
  ctk_plugin_context_->registerService<ctkEventHandler>(this, ctk_dic);
}

PublisherPlugin::~PublisherPlugin() {}

QWidget* PublisherPlugin::CreateWidget() { return publisher_plugin_widget_; }

void PublisherPlugin::InitWidget() {}

QString PublisherPlugin::GetDockObjectName() {
  return QString("PublisherPluginDockWidget");
}

QString PublisherPlugin::GetDockWidgetName() { return QString(); }

Qt::DockWidgetArea PublisherPlugin::GetDockWidgetArea() {
  return Qt::DockWidgetArea();
}

QDockWidget::DockWidgetFeatures PublisherPlugin::GetDockFeatures() {
  return QDockWidget::DockWidgetFeatures();
}

void PublisherPlugin::sayHello() {}

void PublisherPlugin::sayHok() {}

void PublisherPlugin::handleEvent(const ctkEvent& event) {
  // 接收监听事件接口
  if (event.getTopic() == "mesg") {
    QVariant data1 = event.getProperty(event.getTopic());
    data mesg = data1.value<data>();
    qDebug() << mesg.x << mesg.y << mesg.z;
  }
}

void PublisherPlugin::SendLog(const QString plugin_name, const int level,
                              const QString log) {}

void PublisherPlugin::SendEvent(const QString topic, const ctkDictionary& obj) {
}
